﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;

namespace Kkc.Application.Specifications
{
    public abstract class UnarySpecification<T>: Specification<T>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UnarySpecification&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="expression">The expression.</param>
        protected UnarySpecification(ISpecification<T> specification)
        {
            if (specification == null)
                throw new ArgumentNullException("specification");

            expression = CreateUnaryExpression(specification.Expression);
        }

        protected abstract Expression<Func<T, bool>> CreateUnaryExpression(Expression<Func<T, bool>> nestedExpression);

        private readonly Expression<Func<T, bool>> expression;

        public override Expression<Func<T, bool>> Expression
        {
            get { return expression; }
        }
        
    }
}